﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pheonix.Fashionzoomer.DAL;

/// <summary>
/// Summary description for CustomDropdown
/// </summary>

[assembly: TagPrefix("Pheonix.CodeLibrary.Web", "CustomControl")]
namespace Pheonix.Fashionzoomer.UI
{
    [SupportsEventValidation, ValidationProperty("SelectedValue")]
    [ToolboxData("<{0}:CountryDropDown runat=server></{0}:CountryDropDown>")]
    public class CategoryDropdown : DropDownList
    {
        public override void DataBind()
        {
            EnableViewState = false;

            DataTable categoryList = CustomCommand.GetCategoryForDropdown();
            this.DataTextField = "category_name";
            this.DataValueField = "id";
            this.DataSource = categoryList;

            //inserting 'top' item
            if (FirstItem != string.Empty)
            {
                this.Items.Insert(0, new ListItem(FirstItem, "-1"));
            }

            base.DataBind();
        }

        string _firstItem = "None";
        public string FirstItem
        {
            get { return _firstItem; }
            set { _firstItem = value; }
        }

        public override string SelectedValue
        {
            get
            {
                return base.SelectedValue;
            }
            set
            {
                if (value != null)
                    base.SelectedValue = value;
            }

        }
    }
}
